package com.geekgo.callablefuture;

import java.io.File;
import java.util.Scanner;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 *
 * @author HeHaoyang
 * @version 2016/6/12 18:23
 */
public class FutureTest {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter starting directory:");
        String d = in.nextLine();
        System.out.println("Enter keyword:");
        String key = in.nextLine();
        FileCounter fileCounter = new FileCounter(new File(d), key);
        FutureTask<Integer> futureTask = new FutureTask<Integer>(fileCounter);
        (new Thread(futureTask)).start();

        try {
            int e = futureTask.get();
            System.out.println("找到 " + e + "个文件。");
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

    }
}
